package com.fengmi.controller;

import com.fengmi.entity.MallGoodsCat;
import com.fengmi.entity.ViewCatTemp;
import com.fengmi.service.GoodsCategoryService;
import com.fengmi.service.ViewCatTemplateService;
import com.fengmi.view.ViewCatTpl;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 123
 * @Date 2022/1/25 21:13
 * @Version 1.0
 */

import java.util.List;

@RestController
@RequestMapping("category")
@CrossOrigin
@Api(tags = "商品分类管理")
public class GoodsCategoryController {

    @Autowired
    private GoodsCategoryService categoryService;

    @Autowired
    private ViewCatTemplateService viewCatTemplateService;


    @GetMapping("cascade")
    public ResultVO cascade() {
        return categoryService.selectAllCategoryCascade();
    }

    @GetMapping("findCat/{pid}")
    @ApiOperation("通过父id查询分类信息")
    public ResultVO findCatByParentId(@PathVariable String pid) {
        return categoryService.selectCatByParentId(pid);
    }

    @PostMapping("update")
    @ApiOperation("修改商品分类信息")
    public ResultVO updateGoodsCategory(@RequestBody MallGoodsCat mallGoodsCat) {
        return categoryService.updateCategoryById(mallGoodsCat);
    }



    @GetMapping("findCatListBypId/{pid}")
    public List<ViewCatTpl> findCatListBypId(@PathVariable String pid){

        return  viewCatTemplateService.selectCatByPid(pid);
    }
}